<template>
  <div class="container">
    <div>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="选择月份：">
              <el-date-picker
                v-model="form.valueDay"
                type="month"
                placeholder="选择月份"
                value-format="yyyy-MM"
                :picker-options="pickerOptions"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="班组：">
              <el-select v-model="teamValue" placeholder>
                <el-option
                  v-for="item in teamList"
                  :key="item.CLIENT_NO"
                  :label="item.LNAME"
                  :value="item.CLIENT_NO"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form" style="float: left">
            <el-button size="mini" type="primary" @click="getlistdata"
              >查 询</el-button
            >
            <el-button size="mini" type="success" @click="exportExcel"
              >导 出</el-button
            >
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
      highlight-current-row
      border
    >
      <el-table-column
        prop="CLIENT_NAME"
        label="所属组织机构"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="NAME"
        label="司机姓名"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="LEAVEDAYS"
        label="请假天数"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="LEAVEPID"
        label="请假班次数"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="KGDAYS"
        label="旷工天数"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="JBDAYS"
        label="加班天数"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="JBSID"
        label="加班班次数"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="REALDAYS"
        label="实际作业天数"
        align="center"
      ></el-table-column>
      <!-- <el-table-column
        prop="LINENAME"
        label="作业路线"
        align="center"
      ></el-table-column> -->
      <el-table-column label="操作" width="350">
        <template slot-scope="scope">
          <el-button type="text" @click="handleJB(scope.$index, scope.row)"
            >加班详情</el-button
          >

          <el-button type="text" @click="handleQJ(scope.$index, scope.row)"
            >请假时间详情</el-button
          >
          <!-- <el-button type="text" @click="handleQJAll(scope.$index, scope.row)"
            >请假班次详情</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>

    <!-- 加班详情 -->
    <el-dialog
      title="加班详情"
      :visible.sync="isVisibleJB"
      width="60%"
      :modal="false"
    >
      <el-table :data="jbData" highlight-current-row border>
        <el-table-column
          prop="WORKDATE"
          label="日期"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="SNAME"
          label="班次名称"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="LINENAME"
          label="路线名称"
          align="center"
        ></el-table-column>
      </el-table>
    </el-dialog>

    <!-- 请假时间详情 -->
    <el-dialog
      title="请假时间详情"
      :visible.sync="isVisibleQJ"
      width="60%"
      :modal="false"
    >
      <el-table :data="qjData" highlight-current-row border>
        <el-table-column
          prop="WORKDATE"
          label="日期"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="SNAME"
          label="班次名称"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="LINENAME"
          label="路线名称"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="STARTTIME"
          label="请假开始时间"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="ENDTIME"
          label="请假结束时间"
          align="center"
        ></el-table-column>
      </el-table>
    </el-dialog>

    <!-- 请假班次详情 -->
    <el-dialog
      title="请假班次详情"
      :visible.sync="isVisibleQJAll"
      width="60%"
      :modal="false"
    >
      <el-table :data="qjAllData" highlight-current-row border>
        <el-table-column
          prop="WORKDATE"
          label="日期"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="SNAME"
          label="班次名称"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="LINENAME"
          label="路线名称"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="ONWORKTIME"
          label="上班时间"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="OFFWORKTIME"
          label="下班时间"
          align="center"
        ></el-table-column>
      </el-table>
    </el-dialog>


  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'
import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {
    return {
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      form: {
        radioData: '日',
        valueDay: formatDate(new Date(), 'yyyy-MM'),
        valueMonth: ''
      },
      sData: {},
      teamList: [],
      teamValue: '',
      tableData: [],
      originalData: [],
      jbData: [],
      qjData: [],
      qjAllData: [],
      isVisibleJB: false,
      isVisibleQJ: false,
      isVisibleQJAll: false,
      pickerOptions: {
        disabledDate (time) {
          return time.getTime() > Date.now();;
        },
      }
    }
  },
  created () {
    this.getTeamList()
  },
  methods: {
    async getTeamList () {
      // var url = 'Vehicle/GetGroupList?ClientNo=' + localStorage.getItem('CLIENT_NO') // zxdata
      var url = 'Vehicle/GetLotInfoPB?ClientNo=' + localStorage.getItem('CLIENT_NO')
      let { data } = await this.$Http.get(url)
      // const { data } = await this.$Http.get('DataListCompany/GetTeamListApi?ClientNo=' + localStorage.getItem('CLIENT_NO'))
      this.teamList = data
      // this.teamList.unshift({ "CLIENT_NO": localStorage.getItem('CLIENT_NO'), "CLIENT_NAME": "全部" })
      this.teamValue = data[0].CLIENT_NO
      // this.attendanceMonth.records.teamList = data

      this.getlistdata()
    },
    async getlistdata () {
      this.currentPage = 1;
      var url = 'Vehicle/GetLeaveInfoPB?ClientNo=' + this.teamValue + '&DATEMONTH=' + this.form.valueDay
      const { data } = await this.$Http.get(url)
      this.tableData = data
    },
    // 导出Excel
    exportExcel () {
      let excelName = '司机月作业统计'
      const tHeader = ['所属组织机构', '司机姓名', '请假天数', '请假班次数', '旷工天数', '加班天数', '加班班次数', '实际作业天数']
      const filterVal = [ 'CLIENT_NAME', 'NAME', 'LEAVEDAYS', 'LEAVEPID', 'KGDAYS', 'JBDAYS', 'JBSID', 'REALDAYS']
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },
    // 打开加班详情窗口
    handleJB (index, row) {
      this.sData = Object.assign({}, row);
      this.isVisibleJB = true;
      this.getJBdata()
    },
    async getJBdata () {
      var url = 'Vehicle/GetLeaveJBInfoPB?DRIVERID=' + this.sData.DRIVERID + '&DATEMONTH=' + this.form.valueDay
      // var url = 'Worker/GetLeaveJBDetailInfoPB?VID=' + this.sData.VID + '&DATEMONTH=' + this.form.valueDay
      const { data } = await this.$Http.get(url)
      this.jbData = data
    },
    // 打开请假详情窗口
    handleQJ (index, row) {
      this.sData = Object.assign({}, row);
      this.isVisibleQJ = true;
      this.getQJdata()
    },
    async getQJdata () {
      var url = 'Vehicle/GetLeaveQJInfoPB?DRIVERID=' + this.sData.DRIVERID + '&DATEMONTH=' + this.form.valueDay
      // var url = 'Worker/GetLeaveQJDetailInfoPB?VID=' + this.sData.VID + '&DATEMONTH=' + this.form.valueDay
      const { data } = await this.$Http.get(url)
      this.qjData = data
    },
    handleQJAll (index, row) {
      this.sData = Object.assign({}, row);
      this.isVisibleQJAll = true;
      this.getQJAlldata()
    },
    async getQJAlldata () {
      var url = 'Vehicle/GetLeaveXQInfoPB?DRIVERID=' + this.sData.DRIVERID + '&DATEMONTH=' + this.form.valueDay
      // var url = 'Worker/GetLeaveQJDetailInfoPB?VID=' + this.sData.VID + '&DATEMONTH=' + this.form.valueDay
      const { data } = await this.$Http.get(url)
      this.qjAllData = data
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
</style>